﻿using CommonConfig;
using SmartBusinessCardEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using WXEntity;

namespace SmartBusinessCardService.Services
{
    /// <summary>
    /// WXServer 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    [ScriptService]
    public class WXServer : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public void GetCards()
        {
            System.Web.HttpContext.Current.Response.Write("hello");
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public void Register(string openid, string name, string sex, string avatarurl)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("openid", openid);
            keyValuePairs.Add("name", name);
            keyValuePairs.Add("sex", sex);
            keyValuePairs.Add("avatarurl", avatarurl);
            RequestServer requestServer = new RequestServer();
            string json = requestServer.WXPost("10000101", keyValuePairs);
            System.Web.HttpContext.Current.Response.Write(json);
        }
        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public void Login(string code)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("code", code);
            RequestServer requestServer = new RequestServer();
            string json = requestServer.WXPost("10000102", keyValuePairs);
            HttpContext.Current.Response.Write(json);
        }


    }
}
